import { t } from '@src/locales'

type OptionItemType = {
  text: string,
  value: string | number | null,
}
// 生成option
function genOptionItem (text: string, value: string | number | null): OptionItemType {
  return {text, value};
} 

// 派单方式 数据转换
export const AllotTypeConvertMap: { [x: string]:  number } = {
  [t('common.base.all')]: 0,
  [t('task.detail.components.manualDispatch')]: 1,
  [t('task.detail.components.poolDispatch')]: 2,
  [t('task.detail.components.autoDispatch')]: 3
}
export const AllotTypeConvertOptions = Object.keys(AllotTypeConvertMap).map(text => genOptionItem(text, AllotTypeConvertMap[text]))

// 工单标记 数据转换
export const FlagConvertMap: { [x: string]: string } = {
  [t('common.task.exceptionStatus.allot')]: 'REALLOT',
  [t('common.task.exceptionStatus.offed')]: 'OFFED',
  [t('common.task.exceptionStatus.refused')]: 'REFUSED',
  [t('common.task.exceptionStatus.pause')]: 'PAUSED',
  [t('common.task.exceptionStatus.rollback')]: 'ROLLBACK',
  [t('common.task.exceptionStatus.overTime')]: 'OVER_TIME',
  [t('common.task.exceptionStatus.onceAllot')]: 'ONCE_REALLOT',
  [t('common.task.exceptionStatus.onceOverTime')]: 'ONCEOVERTIME',
  [t('common.task.exceptionStatus.onceRefused')]: 'ONCEREFUSED',
  [t('common.task.exceptionStatus.oncePaused')]: 'ONCEPAUSED',
  [t('common.task.exceptionStatus.onceRollback')]: 'ONCEROLLBACK',
  [t('common.task.exceptionStatus.positionException')]: 'POSITIONEXCEPTION'
}
export const FlagConvertOptions = Object.keys(FlagConvertMap).map(text => genOptionItem(text, FlagConvertMap[text]))

export const TaskSearchInputPlaceholderMap: Record<string, string> = {
  default: t('task.model.tip.searchTaskTip1'),
  [t('task.model.byTaskRemark')]: t('task.model.tip.searchTaskTip2'),
  [t('task.model.byTaskCard')]: t('task.model.tip.searchTaskTip3')
}

export const TaskOnceConvertMap: { [x: string]:  number | null } = {
  [t('common.base.all')]: null,
  [t('common.base.yes')]: 1,
  [t('common.base.no')]: 0,
}
export const TaskOnceConvertOptions = [
  { text: t('common.base.yes'), value: '1' },
  { text: t('common.base.no'), value: '0' },
]


export const TaskApproveConvertMap: { [x: string]:  number | null } = {
  [t('common.base.all')]: null,
  [t('common.task.approveStatus.approve')]: 1,
  [t('common.task.approveStatus.noApprove')]: 0
}

export const TaskApproveConvertOptions = [
  { text: t('common.task.approveStatus.approve'), value: '1' },
  { text: t('common.task.approveStatus.noApprove'), value: '0' },
]
